package com.ruoyi.iot.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.iot.domain.DeviceWeather;
import com.ruoyi.iot.service.IDeviceWeatherService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 气象站数据Controller
 *
 * @author rww
 * @date 2023-09-20
 */
@RestController
@RequestMapping("/iot/weather")
public class DeviceWeatherController extends BaseController
{
    @Autowired
    private IDeviceWeatherService deviceWeatherService;

    /**
     * 查询气象站数据列表
     */
    @PreAuthorize("@ss.hasPermi('DeviceWeather:weather:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceWeather deviceWeather)
    {
        startPage();
        List<DeviceWeather> list = deviceWeatherService.selectDeviceWeatherList(deviceWeather);
        return getDataTable(list);
    }

    /**
     * 导出气象站数据列表
     */
    @PreAuthorize("@ss.hasPermi('DeviceWeather:weather:export')")
    @Log(title = "气象站数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceWeather deviceWeather)
    {
        List<DeviceWeather> list = deviceWeatherService.selectDeviceWeatherList(deviceWeather);
        ExcelUtil<DeviceWeather> util = new ExcelUtil<DeviceWeather>(DeviceWeather.class);
        util.exportExcel(response, list, "气象站数据数据");
    }

    /**
     * 获取气象站数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('DeviceWeather:weather:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deviceWeatherService.selectDeviceWeatherById(id));
    }

    /**
     * 新增气象站数据
     */
    @PreAuthorize("@ss.hasPermi('DeviceWeather:weather:add')")
    @Log(title = "气象站数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceWeather deviceWeather)
    {
        return toAjax(deviceWeatherService.insertDeviceWeather(deviceWeather));
    }

    /**
     * 修改气象站数据
     */
    @PreAuthorize("@ss.hasPermi('DeviceWeather:weather:edit')")
    @Log(title = "气象站数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceWeather deviceWeather)
    {
        return toAjax(deviceWeatherService.updateDeviceWeather(deviceWeather));
    }

    /**
     * 删除气象站数据
     */
    @PreAuthorize("@ss.hasPermi('DeviceWeather:weather:remove')")
    @Log(title = "气象站数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deviceWeatherService.deleteDeviceWeatherByIds(ids));
    }
}
